{% extends "WallabagCoreBundle::layout.html.twig" %}

{% block title %}{{ 'config.page_title'|trans }}{% endblock %}

{% block content %}
    <h2>{{ 'config.tab_menu.settings'|trans }}</h2>

    {{ form_start(form.config) }}
        {{ form_errors(form.config) }}

        <fieldset class="w500p inline">
            <div class="row">
                {{ form_label(form.config.theme) }}
                {{ form_errors(form.config.theme) }}
                {{ form_widget(form.config.theme) }}
            </div>
            <a href="#" title="{{ 'config.form_settings.help_theme'|trans }}">
                <i class="material-icons">live_help</i>
            </a>
        </fieldset>

        <fieldset class="w500p inline">
            <div class="row">
                {{ form_label(form.config.items_per_page) }}
                {{ form_errors(form.config.items_per_page) }}
                {{ form_widget(form.config.items_per_page) }}
            </div>
            <a href="#" title="{{ 'config.form_settings.help_items_per_page'|trans }}">
                <i class="material-icons">live_help</i>
            </a>
        </fieldset>

        <fieldset class="w500p inline">
            <div class="row">
                {{ form_label(form.config.reading_speed) }}
                {{ form_errors(form.config.reading_speed) }}
                {{ form_widget(form.config.reading_speed) }}
                <p>
                    {{ 'config.form_settings.reading_speed.help_message'|trans }}
                    <a href="https://wallabag.github.io/myreadspeed/">myreadspeed</a>
                </p>
            </div>
            <a href="#" title="{{ 'config.form_settings.help_reading_speed'|trans }}">
                <i class="material-icons">live_help</i>
            </a>
        </fieldset>

        <fieldset class="w500p inline">
            <div class="row">
                {{ form_label(form.config.action_mark_as_read) }}
                {{ form_errors(form.config.action_mark_as_read) }}
                {{ form_widget(form.config.action_mark_as_read) }}
            </div>
        </fieldset>

        <fieldset class="w500p inline">
            <div class="row">
                {{ form_label(form.config.language) }}
                {{ form_errors(form.config.language) }}
                {{ form_widget(form.config.language) }}
            </div>
            <a href="#" title="{{ 'config.form_settings.help_language'|trans }}">
                <i class="material-icons">live_help</i>
            </a>
        </fieldset>

        <fieldset class="w500p inline">
            <div class="row">
                {{ form_label(form.config.pocket_consumer_key) }}
                {{ form_errors(form.config.pocket_consumer_key) }}
                {{ form_widget(form.config.pocket_consumer_key) }}
                <p>
                    &raquo;
                    <a href="https://getpocket.com/developer/docs/authentication">https://getpocket.com/developer/docs/authentication</a>
                </p>
            </div>
            <a href="#" title="{{ 'config.form_settings.help_pocket_consumer_key'|trans }}">
                <i class="material-icons">live_help</i>
            </a>
        </fieldset>

        <fieldset class="w500p inline">
            <div class="row">
                <h3>{{ 'config.form_settings.android_configuration'|trans }}</h3>
                <a href="wallabag://{{ app.user.username }}@{{ wallabag_url }}">{{ 'config.form_settings.android_instruction' | trans }}</a>
                <br/>
                <img id="androidQrcode" alt="{{ 'config.otp.app.qrcode_label' | trans }}" />
                <script>
                    document.getElementById('androidQrcode').src = jrQrcode.getQrBase64('wallabag://{{ app.user.username }}@{{ wallabag_url }}');
                </script>
            </div>
        </fieldset>

        {{ form_rest(form.config) }}
    </form>

    <h2>{{ 'config.tab_menu.feed'|trans }}</h2>

        {{ form_start(form.feed) }}
        {{ form_errors(form.feed) }}

        <div class="row">
            {{ 'config.form_feed.description'|trans }}
        </div>

        <fieldset class="w500p inline">
            <div class="row">
                <label>{{ 'config.form_feed.token_label'|trans }}</label>
                {% if feed.token %}
                    {{ feed.token }}
                {% else %}
                    <em>{{ 'config.form_feed.no_token'|trans }}</em>
                {% endif %}

                {% if feed.token %}
                    – <a href="{{ path('generate_token') }}">{{ 'config.form_feed.token_reset'|trans }}</a>
                    – <a href="{{ path('revoke_token') }}">{{ 'config.form_feed.token_revoke'|trans }}</a>
                {% else %}
                    – <a href="{{ path('generate_token') }}">{{ 'config.form_feed.token_create'|trans }}</a>
                {% endif %}
            </div>
        </fieldset>

        {% if feed.token %}
        <fieldset class="w500p inline">
            <div class="row">
                <label>{{ 'config.form_feed.feed_links'|trans }}</label>
                <ul>
                    <li><a href="{{ path('unread_feed', {'username': feed.username, 'token': feed.token}) }}">{{ 'config.form_feed.feed_link.unread'|trans }}</a></li>
                    <li><a href="{{ path('starred_feed', {'username': feed.username, 'token': feed.token}) }}">{{ 'config.form_feed.feed_link.starred'|trans }}</a></li>
                    <li><a href="{{ path('archive_feed', {'username': feed.username, 'token': feed.token}) }}">{{ 'config.form_feed.feed_link.archive'|trans }}</a></li>
                    <li><a href="{{ path('all_feed', {'username': feed.username, 'token': feed.token}) }}">{{ 'config.form_feed.feed_link.all'|trans }}</a></li>
                </ul>
            </div>
        </fieldset>
        {% endif %}

        <fieldset class="w500p inline">
            <div class="row">
                {{ form_label(form.feed.feed_limit) }}
                {{ form_errors(form.feed.feed_limit) }}
                {{ form_widget(form.feed.feed_limit) }}
            </div>
        </fieldset>

        {{ form_rest(form.feed) }}
    </form>

    <h2>{{ 'config.tab_menu.user_info'|trans }}</h2>

    {{ form_start(form.user) }}
        {{ form_errors(form.user) }}
        <fieldset class="w500p inline">
            <div class="row">
                <label>{{ 'config.form_user.login_label'|trans }}</label>
                {{ app.user.username }}
            </div>
        </fieldset>

        <fieldset class="w500p inline">
            <div class="row">
                {{ form_label(form.user.name) }}
                {{ form_errors(form.user.name) }}
                {{ form_widget(form.user.name) }}
            </div>
        </fieldset>

        <fieldset class="w500p inline">
            <div class="row">
                {{ form_label(form.user.email) }}
                {{ form_errors(form.user.email) }}
                {{ form_widget(form.user.email) }}
            </div>
        </fieldset>

        {{ form_widget(form.user.save) }}

        {% if twofactor_auth %}
        <h5>{{ 'config.otp.page_title'|trans }}</h5>

        <div class="row">
            {{ 'config.form_user.two_factor_description'|trans }}
        </div>

        <table>
            <thead>
                <tr>
                    <th>{{ 'config.form_user.two_factor.table_method'|trans }}</th>
                    <th>{{ 'config.form_user.two_factor.table_state'|trans }}</th>
                    <th>{{ 'config.form_user.two_factor.table_action'|trans }}</th>
                </tr>
            </thead>

            <tbody>
                <tr>
                    <td>{{ 'config.form_user.two_factor.emailTwoFactor_label'|trans }}</td>
                    <td>{% if app.user.isEmailTwoFactor %}<b>{{ 'config.form_user.two_factor.state_enabled'|trans }}</b>{% else %}{{ 'config.form_user.two_factor.state_disabled'|trans }}{% endif %}</td>
                    <td><a href="{{ path('config_otp_email') }}" class="waves-effect waves-light btn{% if app.user.isEmailTwoFactor %} disabled{% endif %}">{{ 'config.form_user.two_factor.action_email'|trans }}</a>  {% if app.user.isEmailTwoFactor %}<a href="{{ path('disable_otp_email') }}" class="waves-effect waves-light btn">Disable</a>{% endif %}</td>
                </tr>
                <tr>
                    <td>{{ 'config.form_user.two_factor.googleTwoFactor_label'|trans }}</td>
                    <td>{% if app.user.isGoogleTwoFactor %}<b>{{ 'config.form_user.two_factor.state_enabled'|trans }}</b>{% else %}{{ 'config.form_user.two_factor.state_disabled'|trans }}{% endif %}</td>
                    <td><a href="{{ path('config_otp_app') }}" class="waves-effect waves-light btn{% if app.user.isGoogleTwoFactor %} disabled{% endif %}">{{ 'config.form_user.two_factor.action_app'|trans }}</a> {% if app.user.isGoogleTwoFactor %}<a href="{{ path('disable_otp_app') }}" class="waves-effect waves-light btn">Disable</a>{% endif %}</td>
                </tr>
            </tbody>
        </table>

        {% endif %}

        {{ form_widget(form.user._token) }}
    </form>

    {% if enabled_users > 1 %}
        <h2>{{ 'config.form_user.delete.title'|trans }}</h2>

        <p>{{ 'config.form_user.delete.description'|trans }}</p>
        <a href="{{ path('delete_account') }}" onclick="return confirm('{{ 'config.form_user.delete.confirm'|trans|escape('js') }}')" class="waves-effect waves-light btn red delete-account">
            {{ 'config.form_user.delete.button'|trans }}
        </a>
    {% endif %}

    <h2>{{ 'config.tab_menu.password'|trans }}</h2>

    {{ form_start(form.pwd) }}
        {{ form_errors(form.pwd) }}

        <div class="row">
            {{ 'config.form_password.description'|trans }}
        </div>

        <fieldset class="w500p inline">
            <div class="row">
                {{ form_label(form.pwd.old_password) }}
                {{ form_errors(form.pwd.old_password) }}
                {{ form_widget(form.pwd.old_password) }}
            </div>
        </fieldset>

        <fieldset class="w500p inline">
            <div class="row">
                {{ form_label(form.pwd.new_password.first) }}
                {{ form_errors(form.pwd.new_password.first) }}
                {{ form_widget(form.pwd.new_password.first) }}
            </div>
        </fieldset>

        <fieldset class="w500p inline">
            <div class="row">
                {{ form_label(form.pwd.new_password.second) }}
                {{ form_errors(form.pwd.new_password.second) }}
                {{ form_widget(form.pwd.new_password.second) }}
            </div>
        </fieldset>

        {{ form_rest(form.pwd) }}
    </form>

    <h2>{{ 'config.tab_menu.rules'|trans }}</h2>

    <ul>
        {% for tagging_rule in app.user.config.taggingRules %}
        <li>
            {{ 'config.form_rules.if_label'|trans }}
            « {{ tagging_rule.rule }} »
            {{ 'config.form_rules.then_tag_as_label'|trans }}
            « {{ tagging_rule.tags|join(', ') }} »
            <a href="{{ path('edit_tagging_rule', {id: tagging_rule.id}) }}" title="{{ 'config.form_rules.edit_rule_label'|trans }}" class="tool mode_edit">✎</a>
            <a href="{{ path('delete_tagging_rule', {id: tagging_rule.id}) }}" title="{{ 'config.form_rules.delete_rule_label'|trans }}" class="tool delete icon-trash icon"></a>
        </li>
        {% endfor %}
    </ul>

    {{ form_start(form.new_tagging_rule) }}
        {{ form_errors(form.new_tagging_rule) }}

        <fieldset class="w500p inline">
            <div class="row">
                {{ form_label(form.new_tagging_rule.rule) }}
                {{ form_errors(form.new_tagging_rule.rule) }}
                {{ form_widget(form.new_tagging_rule.rule) }}
            </div>
        </fieldset>

        <fieldset class="w500p inline">
            <div class="row">
                {{ form_label(form.new_tagging_rule.tags) }}
                {{ form_errors(form.new_tagging_rule.tags) }}
                {{ form_widget(form.new_tagging_rule.tags) }}
            </div>
        </fieldset>

        {{ form_rest(form.new_tagging_rule) }}
    </form>

    <div class="row">
        <h3>{{ 'config.form_rules.card.import_tagging_rules'|trans }}</h3>
        <p>{{ 'config.form_rules.card.import_tagging_rules_detail'|trans }}</p>
    </div>

    {{ form_start(form.import_tagging_rule) }}
        {{ form_errors(form.import_tagging_rule) }}

        <fieldset class="w500p inline">
            <div class="row">
                {{ form_label(form.import_tagging_rule.file) }}
                {{ form_errors(form.import_tagging_rule.file) }}
                {{ form_widget(form.import_tagging_rule.file) }}
            </div>
        </fieldset>

        {{ form_rest(form.import_tagging_rule) }}
    </form>

    {% if app.user.config.taggingRules is not empty %}
    <div class="row">
        <h3>{{ 'config.form_rules.card.export_tagging_rules'|trans }}</h3>
        <p>{{ 'config.form_rules.card.export_tagging_rules_detail'|trans }}</p>
        <p><a href="{{ path('export_tagging_rule') }}" class="waves-effect waves-light btn">{{ 'config.form_rules.export'|trans }}</a></p>
    </div>
    {% endif %}

    <div class="row">
        <div class="input-field col s12">
            <h3>{{ 'config.form_rules.faq.title'|trans }}</h3>

            <h4>{{ 'config.form_rules.faq.tagging_rules_definition_title'|trans }}</h4>
            <p class="help">{{ 'config.form_rules.faq.tagging_rules_definition_description'|trans|raw }}</p>

            <h4>{{ 'config.form_rules.faq.how_to_use_them_title'|trans }}</h4>
            <p class="help">{{ 'config.form_rules.faq.how_to_use_them_description'|trans|raw }}</p>

            <h4>{{ 'config.form_rules.faq.variables_available_title'|trans }}</h4>
            <p class="help">
                {{ 'config.form_rules.faq.variables_available_description'|trans }}
            </p>

            <table class="bordered">
                <thead>
                <tr>
                    <th>{{ 'config.form_rules.faq.variable_description.label'|trans }}</th>
                    <th>{{ 'config.form_rules.faq.meaning'|trans }}</th>
                    <th>{{ 'config.form_rules.faq.operator_description.label'|trans }}</th>
                    <th>{{ 'config.form_rules.faq.meaning'|trans }}</th>
                </tr>
                </thead>

                <tbody>
                <tr>
                    <td>title</td>
                    <td>{{ 'config.form_rules.faq.variable_description.title'|trans }}</td>
                    <td>&lt;=</td>
                    <td>{{ 'config.form_rules.faq.operator_description.less_than'|trans }}</td>
                </tr>
                <tr>
                    <td>url</td>
                    <td>{{ 'config.form_rules.faq.variable_description.url'|trans }}</td>
                    <td>&lt;</td>
                    <td>{{ 'config.form_rules.faq.operator_description.strictly_less_than'|trans }}</td>
                </tr>
                <tr>
                    <td>isArchived</td>
                    <td>{{ 'config.form_rules.faq.variable_description.isArchived'|trans }}</td>
                    <td>&gt;=</td>
                    <td>{{ 'config.form_rules.faq.operator_description.greater_than'|trans }}</td>
                </tr>
                <tr>
                    <td>isStarred</td>
                    <td>{{ 'config.form_rules.faq.variable_description.isStarred'|trans }}</td>
                    <td>&gt;</td>
                    <td>{{ 'config.form_rules.faq.operator_description.strictly_greater_than'|trans }}</td>
                </tr>
                <tr>
                    <td>content</td>
                    <td>{{ 'config.form_rules.faq.variable_description.content'|trans }}</td>
                    <td>=</td>
                    <td>{{ 'config.form_rules.faq.operator_description.equal_to'|trans }}</td>
                </tr>
                <tr>
                    <td>language</td>
                    <td>{{ 'config.form_rules.faq.variable_description.language'|trans }}</td>
                    <td>!=</td>
                    <td>{{ 'config.form_rules.faq.operator_description.not_equal_to'|trans }}</td>
                </tr>
                <tr>
                    <td>mimetype</td>
                    <td>{{ 'config.form_rules.faq.variable_description.mimetype'|trans }}</td>
                    <td>OR</td>
                    <td>{{ 'config.form_rules.faq.operator_description.or'|trans }}</td>
                </tr>
                <tr>
                    <td>readingTime</td>
                    <td>{{ 'config.form_rules.faq.variable_description.readingTime'|trans }}</td>
                    <td>AND</td>
                    <td>{{ 'config.form_rules.faq.operator_description.and'|trans }}</td>
                </tr>
                <tr>
                    <td>domainName</td>
                    <td>{{ 'config.form_rules.faq.variable_description.domainName'|trans }}</td>
                    <td>matches</td>
                    <td>{{ 'config.form_rules.faq.operator_description.matches'|trans|raw }}</td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>

    <h2>{{ 'config.tab_menu.ignore_origin'|trans }}</h2>

    <ul>
        {% for ignore_origin_rule in app.user.config.ignoreOriginRules %}
            <li>
                {{ 'config.form_rules.if_label'|trans }}
                « {{ ignore_origin_rule.rule }} »
                <a href="{{ path('edit_ignore_origin_rule', {id: ignore_origin_rule.id}) }}" title="{{ 'config.form_rules.edit_rule_label'|trans }}" class="tool mode_edit">✎</a>
                <a href="{{ path('delete_ignore_origin_rule', {id: ignore_origin_rule.id}) }}" title="{{ 'config.form_rules.delete_rule_label'|trans }}" class="tool delete icon-trash icon"></a>
            </li>
        {% endfor %}
    </ul>

    {{ form_start(form.new_ignore_origin_user_rule) }}
        {{ form_errors(form.new_ignore_origin_user_rule) }}

        <fieldset class="w500p inline">
            <div class="row">
                {{ form_label(form.new_ignore_origin_user_rule.rule) }}
                {{ form_errors(form.new_ignore_origin_user_rule.rule) }}
                {{ form_widget(form.new_ignore_origin_user_rule.rule) }}
            </div>
        </fieldset>

        {{ form_rest(form.new_ignore_origin_user_rule) }}
    </form>

    <div class="row">
        <div class="input-field col s12">
            <h4>{{ 'config.form_ignore_origin_rules.faq.title'|trans }}</h4>

            <h5>{{ 'config.form_ignore_origin_rules.faq.ignore_origin_rules_definition_title'|trans }}</h5>
            <p class="help">{{ 'config.form_ignore_origin_rules.faq.ignore_origin_rules_definition_description'|trans|raw }}</p>

            <h5>{{ 'config.form_ignore_origin_rules.faq.how_to_use_them_title'|trans }}</h5>
            <p class="help">{{ 'config.form_ignore_origin_rules.faq.how_to_use_them_description'|trans|raw }}</p>

            <h5>{{ 'config.form_ignore_origin_rules.faq.variables_available_title'|trans }}</h5>
            <p class="help">
                {{ 'config.form_ignore_origin_rules.faq.variables_available_description'|trans }}
            </p>

            <table class="bordered">
                <thead>
                    <tr>
                        <th>{{ 'config.form_ignore_origin_rules.faq.variable_description.label'|trans }}</th>
                        <th>{{ 'config.form_ignore_origin_rules.faq.meaning'|trans }}</th>
                        <th>{{ 'config.form_ignore_origin_rules.faq.operator_description.label'|trans }}</th>
                        <th>{{ 'config.form_ignore_origin_rules.faq.meaning'|trans }}</th>
                    </tr>
                </thead>

                <tbody>
                    <tr>
                        <td>host</td>
                        <td>{{ 'config.form_ignore_origin_rules.faq.variable_description.host'|trans }}</td>
                        <td>=</td>
                        <td>{{ 'config.form_ignore_origin_rules.faq.operator_description.equal_to'|trans }}</td>
                    </tr>
                    <tr>
                        <td>_all</td>
                        <td>{{ 'config.form_ignore_origin_rules.faq.variable_description._all'|trans }}</td>
                        <td>~</td>
                        <td>{{ 'config.form_ignore_origin_rules.faq.operator_description.matches'|trans|raw }}</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>

    <h2>{{ 'config.reset.title'|trans }}</h2>
    <fieldset class="w500p inline">
        <p>{{ 'config.reset.description'|trans }}</p>
        <ul>
            <li>
                <a href="{{ path('config_reset', { type: 'annotations'}) }}" onclick="return confirm('{{ 'config.reset.confirm'|trans|escape('js') }}')" class="waves-effect waves-light btn red">
                    {{ 'config.reset.annotations'|trans }}
                </a>
            </li>
            <li>
                <a href="{{ path('config_reset', { type: 'tags'}) }}" onclick="return confirm('{{ 'config.reset.confirm'|trans|escape('js') }}')" class="waves-effect waves-light btn red">
                    {{ 'config.reset.tags'|trans }}
                </a>
            </li>
            <li>
                <a href="{{ path('config_reset', { type: 'archived'}) }}" onclick="return confirm('{{ 'config.reset.confirm'|trans|escape('js') }}')" class="waves-effect waves-light btn red">
                    {{ 'config.reset.archived'|trans }}
                </a>
            </li>
            <li>
                <a href="{{ path('config_reset', { type: 'entries'}) }}" onclick="return confirm('{{ 'config.reset.confirm'|trans|escape('js') }}')" class="waves-effect waves-light btn red">
                    {{ 'config.reset.entries'|trans }}
                </a>
            </li>
        </ul>
    </fieldset>
{% endblock %}
